package com.sunreal.paygateway.api.controller;


import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.sunreal.paygateway.dao.TestDTO;
import com.sunreal.paygateway.dao.vo.SunrealPayOrder;
import com.sunreal.paygateway.sys.annotations.RequestSign;
import com.sunreal.paygateway.sys.annotations.ResponseEncode;
import com.sunreal.paygateway.sys.annotations.ResponseSign;
import com.sunreal.paygateway.sys.common.SecurityMethod;
import com.sunreal.paygateway.sys.util.result.WebResult;

/**
 * 功能描述：//TODO
 *
 * @Author 彭广
 * @Date 2019/1/21
 */
@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
public class TestController {

    @PostMapping("/api/test/ttt")
    @RequestSign
    @ResponseSign
    public WebResult Test(@RequestBody TestDTO json, HttpServletRequest request) {
        WebResult result = new WebResult();
//        TestDTO test = GsonUtil.fromJson(json, TestDTO.class);
//        System.out.println(test.toString());
        json.setSign("");
        SunrealPayOrder order = new SunrealPayOrder();
        order.setMchid("1");
        order.setMchorderno("112432134222");
        order.setAmount(1L);
        order.setChannelid("WX_NATIVE");
        order.setCurrency("CNY");
        order.setNotifyurl("http://192.168.100.24:8080/newframe/api/payorder/testPayResult.html");
        order.setReturnurl("http://192.168.100.24:8080/newframe");
        order.setSubject("微信支付测试订单名称");
        order.setBody("微信支付测试商品描述");
        order.setOriginalorderid("112432134222");

        order.setUpdatetime(1555450099000L);
        order.setCreatetime(1555450099000L);
        order.setNotifycount(0L);
        order.setStatus(0L);
        JSONObject info = new JSONObject();
        info.put("productId", "9");
        order.setExtra(info.toJSONString());
        result.isOK();
        result.setData(order);
        result.setMsg("这其实是个测试");
        return result;
    }
    @PostMapping("/api/test/2")
    @RequestSign
    @ResponseSign
    @ResponseEncode(SecurityMethod.RSA)
    public WebResult test2(){
        WebResult result = new WebResult();
        SunrealPayOrder order = new SunrealPayOrder();
        order.setMchid("1");
        result.isOK();
        result.setData(order);
        result.setMsg("这其实是个测试");
        return result;
    }


}
